define(['jquery', 'bootstrap', 'utilback', 'table', 'form', 'myfileinput','upload'], function ($, undefined, Utilback, Table, Form,myfileInput,Upload) {

    var Controller = {
    	config: {
    		get_url: '/user/read/detail', // 获取用户详情
            get_param: '/param/read/detail',
    	},
        init: function () {
            this.initDic();
            this.initParam();
            this.initParam2();
        },
        initDic:function(){
            // 初始化表格参数配置
            $('[href="#dic"]').on('click',function(){
                Table.api.init({
                    singleSelect: true,
                        extend: {
                            index_url: './json/runReveal.json', // 查询列表
                            add_url: 'runRevealAdd.html', // 新增页面
                            edit_url: 'runRevealAdd.html', // 修改页面
                            guidIn_url:'driverGuidIn.html',//添加导入页面
                            del_url: '/runReveal', // 删除
                            multi_url: '/runReveal',
                            info_url:'',
                            goto_url:'goto.html',
                        }
                    });
                 })
            $('[href="#dic"]').click();
            var table = $("#dicTable");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                toolbar:'#toolbar1',
                method:'get',
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID'},
                        {field: 'revealData', title: '运行揭示日期'},
                        {field: 'orderNum', title: "命令号码"},
                        {field: 'orderContent', title: "命令内容"},
                        {field: 'orderStation', title: "发令台"},
                        {field: 'goTo', title: "转至"},
                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                if(row.userType == 3) {
                                    return '';
                                }
                                return Table.api.formatter.operate.call(this, value, row, index, table);
                            }}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            $('.btn-goto').click(function(){
                var ids = Table.api.selectedids(table);
                var options = table.bootstrapTable('getOptions');
                var url = options.extend.goto_url + (options.extend.goto_url.match(/(\?|&)+/) ? "&id=" : "?id=") + ids.join(",") + '&t=A';
                Util.api.open(url, '转至',300,200);
            })

        },
        initParam:function(){
            var i = 0;
            $('[href="#param"]').on('click',function(){
                Table.api.init({
                    singleSelect:true,
                    search:false,
                    commonSearch:false,
                    searchFormVisible:false,
                    showColumns:false,
                    extend:{
                        index_url: './json/runReveal.json', // 查询列表
                        del_url: '/user', // 删除
                        multi_url: '/user',
                        info_url:'',//信息的页面
                    }
                });
                if(i === 0){
                    var paramTable = $("#paramTable");
                    // 初始化表格
                    paramTable.bootstrapTable({
                        toolbar:'#toolbar2',
                        url:$.fn.bootstrapTable.defaults.extend.index_url,
                        method:'get',
                        columns:[
                            [
                                {field:'state',checkbox:true},
                                {field:'id',title:'ID'},
                                {field:'data',title:'运行揭示日期'},
                                {field:'orderNum',title:'命令号码'},
                                {field:'orderContent',title:'命令内容'},
                                {field:'startingStation',title:'发令台'},
                            ]
                        ]
                    });
                    // 为表格绑定事件
                    Table.api.bindevent(paramTable);
                    i++;
                }
            })
        },
        initParam2:function(){
              var i = 0;
            $('[href="#param2"]').on('click',function(){
                Table.api.init({
                    singleSelect:true,
                    search:false,
                    commonSearch:false,
                    searchFormVisible:false,
                    showColumns:false,
                    extend:{
                        index_url: './json/runReveal.json', // 查询列表
                        del_url: '', // 删除
                        multi_url: '/user',
                        info_url:'',//信息的页面
                    }
                });
                if(i === 0){
                    var paramTable = $("#paramTable2");
                    // 初始化表格
                    paramTable.bootstrapTable({
                        toolbar:'#toolbar3',
                        url:$.fn.bootstrapTable.defaults.extend.index_url,
                        method:'get',
                        columns:[
                            [
                                {field:'state',checkbox:true},
                                {field:'id',title:'ID'},
                                {field:'data',title:'运行揭示日期'},
                                {field:'orderNum',title:'命令号码'},
                                {field:'orderContent',title:'命令内容'},
                                {field:'startingStation',title:'发令台'},
                            ]
                        ]
                    });
                    // 为表格绑定事件
                    Table.api.bindevent(paramTable);
                    i++;
                }
            })
        },
        edit: function () { // 初始化编辑页面
            // myfileInput.init.initSubmit('excelFile');//导入事件绑定
            Form.api.bindevent($("form[role=form]"));
            var id = Util.api.query('id');
            var t = Util.api.query('t');
            if(id && t === 'U') {
                Form.api.fill($('#edit-form'), Controller.config.get_dic, id, function(data) {
                });
            }
        },
        update: function() {
            Form.api.bindevent($("form[role=form]"));
        	Util.api.ajax({
        		type: 'get',
        		url: './json/person.json'
        	}, function(data) {
        		$('#edit-form').autofill(data);
        	});
        }
    };
    return Controller;
      function changeAgentContent(){
            document.getElementById("inputFileAgent").value
     = document.getElementById("inputFile").value;
    }
});